layui.use(["form", "ax", "admin"], function () {
    var $ = layui.$;
    var form = layui.form;
    var $ax = layui.ax;
    var admin = layui.admin;

    form.on("select(operType)", function (data) {
        var operTypeVal = data.value;
        if (operTypeVal == "0") {
            $("#level1").attr("lay-verify", "required");
        } else {
            $("#level1").removeAttr("lay-verify");
        }
    });

    form.on('submit(btnSubmit)', function (data) {
        var level1Val = $("#level1").val();
        var level2Val = $("#level2").val();
        var level3Val = $("#level3").val();
        var operTypeVal = $("#operType").val();

        if (operTypeVal == "0" && level1Val != "") {
            if (level2Val != "" && level3Val == "") {
                if (parseFloat(level1Val) >= parseFloat(level2Val)) {
                    Feng.error("告警阈值需满足level1&lt;level2&lt;level3");
                    return false;
                }
            } else if (level2Val == "" && level3Val != "") {
                if (parseFloat(level1Val) >= parseFloat(level3Val)) {
                    Feng.error("告警阈值需满足level1&lt;level2&lt;level3");
                    return false;
                }
            } else if (level2Val != "" && level3Val != "") {
                if (parseFloat(level1Val) >= parseFloat(level2Val) || parseFloat(level2Val) >= parseFloat(level3Val)) {
                    Feng.error("告警阈值需满足level1&lt;level2&lt;level3");
                    return false;
                }
            }
        } else {
            if (level1Val != "" || level2Val != "" || level3Val != "") {
                Feng.error("操作类型为取消时，三级告警阈值均不填!");
                return false;
            }
        }

        var ajax = new $ax(Feng.ctxPath+"/security/simApnGprsAlarm", function (data) {
            layer.open({
                title: "物联卡APN流量告警规则设置办理结果",
                skin: 'layui-layer-molv',
                content: "任务流水号：" + data.data.jobId,
                yes: function (index, layero) {
                    admin.closeThisDialog();
                }
            });
        }, function (data) {
            layer.open({
                content: "设置失败！" + data.responseJSON.message,
                skin: 'layui-layer-molv',
                yes: function (index, layero) {
                    layer.close(index);
                }
            });
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

});